/*
 * @Author: LVGRAPE
 * @LastEditors: LVGRAPE
 */
/***
 * @Author: LVGRAPE
 * @Date: 2023-08-31 10:06:41
 * @LastEditTime: 2025-07-04 22:39:31
 * @LastEditors: LVGRAPE
 * @Description:
 * @FilePath: \zino-fc-v4\ZINO\inc\zino.h
 * @可以输入预定的版权声明、个性签名、空行等
 */

#ifndef __ZINO_H_
#define __ZINO_H_
#ifdef __cplusplus
extern "C"
{
#endif // __cplusplus

#include <rtthread.h>
#include "zino_config.h"
#define ZINO_EXPORT(fn, level)                                                       \
            RT_USED const init_fn_t __zino_init_##fn SECTION(".zino_init_fn." level) = fn
enum pwr_ctrl_type_t {
    PWR_CTRL_NONE = 0,
    PWR_CTRL_SHUTDOWN,
    PWR_CTRL_5V_ON,
    PWR_CTRL_5V_OFF,
    PWR_CTRL_EXT_5V_ON,
    PWR_CTRL_EXT_5V_OFF,

};
/* board init routines will be called in board_init() function */
#define ZINO_BOARD_EXPORT(fn)           ZINO_EXPORT(fn, "1")

/* pre/device/component/env/app init routines will be called in init_thread */
/* components pre-initialization (pure software initialization) */
#define ZINO_PREV_EXPORT(fn)            ZINO_EXPORT(fn, "2")
/* device initialization */
#define ZINO_DEVICE_EXPORT(fn)          ZINO_EXPORT(fn, "3")
/* components initialization (dfs, lwip, ...) */
#define ZINO_COMPONENT_EXPORT(fn)       ZINO_EXPORT(fn, "4")
/* environment initialization (mount disk, ...) */
#define ZINO_ENV_EXPORT(fn)             ZINO_EXPORT(fn, "5")
/* application initialization (rtgui application etc ...) */
#define ZINO_APP_EXPORT(fn)             ZINO_EXPORT(fn, "6")

#define millis() rt_tick_get()
rt_size_t i2c_device_try(const char *i2cbusname, uint8_t addr);
rt_size_t i2c_device_scan(const char *i2cbusname);
long i2c1_scan(void);
long i2c2_scan(void);
rt_size_t zino_pwr_ctrl(enum pwr_ctrl_type_t type);
int motor_init(void);
// void motor_set_freq(uint32_t freq);
// void motor_set_duty(uint8_t mx, uint32_t duty);
uint32_t motor_get_duty(uint8_t mx);
void motor_set_duty_range(uint32_t range);
// void motor_on(uint8_t mx);
// void motor_off(uint8_t mx);
void motor_on_all(void);
void motor_off_all(void);

void rgb_show();
void rgb_set_color(uint8_t index, uint8_t r, uint8_t g, uint8_t b);

// float get_vbat_voltage_mv();
float get_v5_voltage_mv();
float get_v3_3_voltage_mv();
uint16_t get_m1_current_ma();
uint16_t get_m2_current_ma();
uint16_t get_m3_current_ma();
uint16_t get_m4_current_ma();
void keyScanPro_10ms(void);
uint8_t get_pwr_key_action(void);
void clear_pwr_key_action(void);
void set_hb_key_action_callback(void (*callback)(uint8_t times));

void print_dev_info(void);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif
